package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.domain.DataResult;
import com.dongdongshop.em.DataResultEnum;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.service.TbTypeTemplateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("TbTypeTemplateController")
public class TbTypeTemplateController {

    @Reference
    private TbTypeTemplateService tbTypeTemplateService;

    @RequestMapping("ToShow")
    public String ToShow(){

        return "admin/type_template";
    }

    @ResponseBody
    @RequestMapping("listTemplate")
    public DataResult listTemplate(){
       List<TbTypeTemplate> list =  tbTypeTemplateService.listTemplate();
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(list);
    }

    @ResponseBody
    @RequestMapping("toAdd")
    public Boolean toAdd(TbTypeTemplate tbTypeTemplate){
        System.out.println(tbTypeTemplate);
        Boolean b = tbTypeTemplateService.insert(tbTypeTemplate);
        return b;
    }

    @ResponseBody
    @RequestMapping("delete")
    public Boolean delete(Long id){
        Boolean b =tbTypeTemplateService.delete(id);
        return b ;
    }

    @ResponseBody
    @RequestMapping("updata")
    public DataResult updata(Long id){
        TbTypeTemplate tbTypeTemplate = tbTypeTemplateService.selectById(id);
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(tbTypeTemplate);
    }

    @RequestMapping("toupdata")
    @ResponseBody
    public Boolean toupdata(TbTypeTemplate tbTypeTemplate){
        Boolean b = tbTypeTemplateService.updata(tbTypeTemplate);
        return b;
    }
}
